/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

using ll = long long;

constexpr int maxn = 2e5;

int a[maxn + 1];
ll sum[maxn + 1];

void solve() {
  int n, k;
  cin >> n >> k;
  ll tot = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    tot += a[i];
  }
  std::sort(a + 1, a + n + 1);

  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + a[i];
  }

  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans = std::max(ans, tot - sum[n] + sum[n - i] - (sum[(k - i) * 2]));
  }
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Maximum Sum.in", "r", stdin);
  freopen("B. Maximum Sum.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
